package com.yotoodesign.dianba.adapter;

import java.text.DecimalFormat;
import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yotoodesign.dianba.R;
import com.yotoodesign.dianba.bean.BaseData;
import com.yotoodesign.dianba.bean.Ktv;

public class KtvAdapter extends BaseAdapter {

	private Context     mContext;
	private ArrayList<BaseData> ktvList;
	
	

	public ArrayList<BaseData> getKtvList() {
		return ktvList;
	}

	public void setKtvList(ArrayList<BaseData> ktvList) {
		this.ktvList = ktvList;
	}

	public KtvAdapter(Context c){
		this.mContext = c;
	}
	
	@Override
	public int getCount() {
		return ktvList!=null?ktvList.size():0;
	}

	@Override
	public Object getItem(int position) {
		return ktvList!=null?ktvList.get(position):null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = LayoutInflater.from(mContext).inflate(R.layout.ktv_render, null);
		TextView tvKtv = (TextView)view.findViewById(R.id.tvKtv);
		tvKtv.setText((position+1)+"."+((Ktv)ktvList.get(position)).getName());
		
		TextView tvAddress = (TextView)view.findViewById(R.id.tvAddress);
		tvAddress.setText(((Ktv)ktvList.get(position)).getAddr());

		TextView tvPhoneNo = (TextView)view.findViewById(R.id.tvPhoneNo);
		tvPhoneNo.setText(((Ktv)ktvList.get(position)).getPhoneNum());
		
		TextView tvDistance = (TextView)view.findViewById(R.id.tvDistance);
		String dis = new DecimalFormat("#").format(((Ktv)ktvList.get(position)).getDistance());
		tvDistance.setText(dis+"米");
		
		return view;
	}

}
